﻿﻿@{
 ViewBag.Title = "Creating a ASP MVC CRUD application";
 Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Creating a ASP MVC CRUD application</h2>
<h3>Creation of controller</h3>
<p>In  MVC the last piece of the puzzle is creating a controller. In the MVC paradigm, the controller is a class that takes care of performing navigation operations between different razor views, performing validation and database operations. Follow these steps:</p>
<ol>
<li>In Visual Studio, from Solution Explorer, right click Controller folder, and choose Add : Controller:</li>
</ol>
<p align="center"><a href="@Url.Content("~/content/aspmvccrud/images/add_controller.jpg")" data-lightbox="Add Controller Class"><img src="@Url.Content("~/content/aspmvccrud/images/thumbs/add_controller.jpg")" alt="Add Controller Class" width="300" height="50" /></a></p>
<ol start="2">
<li>
In Add Scaffold window:
<ol type="a">
<li>Leave Controller selected</li>
<li>Choose MVC controller with views using Entity Framework</li>
<li>Left click Add:</li>
</ol>
</li>
</ol>
<p align="center"><a href="@Url.Content("~/content/aspmvccrud/images/add_scaffold.jpg")" data-lightbox="Add Scaffold"><img src="@Url.Content("~/content/aspmvccrud/images/thumbs/add_scaffold.jpg")" alt="Add Scaffold" width="300" height="226" /></a></p>
<ol start="3">
<li>
In Add Controller Window:
<ol type="a">
<li>In Controller name, type ApplicantController</li>
<li>In Model class drop down list, choose Applicant (Applicant.Models)</li>
<li>In Data context drop down list, choose ApplicantDataContext (Applicant.DAL)</li>
<li>Left click Add:</li>
</ol>
</li>
</ol>
<p align="center"><a href="@Url.Content("~/content/aspmvccrud/images/add_controller_details.jpg")" data-lightbox="Add Controller Details"><img src="@Url.Content("~/content/aspmvccrud/images/thumbs/add_controller_details.jpg")" alt="Add Controller Details" width="300" height="211" /></a></p>
<p>After clicking Add, we’ll notice that Visual Studio natively creates the following:</p>
<ul class="indent">
<li>An applicant controller with create, read, update, and delete (CRUD) abilities</li>
<li>
Views found at:
<ul>
<li>Views : Applicant</li>
</ul>
</li>
</ul>
<p>Go ahead and run the project and verify our solution is working. Press F5 on the keyboard will show the default landing page. To see our applicant system in the address bar, type the following: http://localhost:&lt;port_number&gt;/Applicant and press enter on the keyboard.</p>
<p>You’ll notice a basic administrative CRUD system. From this point forward we can customize the look and feel of the application, make modifications to our model, data context, and controller classes as well as database modifications. </p>
<h3>Create link to applicant from home page</h3>
<p>Since we don’t want to type the fully qualified web address to our applicant system, let’s add a link to the home page which is found in Views: Shared: _Layout.cshtml:</p>
<pre class="brush:html">
&lt;class="nav navbar-nav"&gt;
&lt;li&gt;Html.ActionLink("Home", "Index", "Home")&lt;/li&gt;
&lt;li&gt;Html.ActionLink("About", "About", "Home")&lt;/li&gt;
&lt;li&gt;Html.ActionLink("Contact", "Contact", "Home")&lt;/li&gt;
&lt;li&gt;Html.ActionLink("Applicant", "Index", "Applicant") &lt;/li&gt;
&lt;/ul&gt;
</pre>
<p>Note: You will need to preface the (at) symbol before each Html helper object.</p>
<p>As you can see from the code we add a link using the html helper object’s class - ActionLink (provided by Razor) and supply the following:</p>
<ol>
<li>
String text:
<ol type="a">
<li>In our example above, Home</li>
</ol>
<li>
Action result name:
<ol type="a">
<li>The name of the action result method we wish to execute in our controller, in our case, the home controller</li>
</ol>
</li>
<li>
Object Values:
<ol type="a">
<li>Maps to the controller your view is working with</li>
</ol>
</li>
</ol>
<p>Save your changes and re-build the solution. Once the build is finished, press F5 on the keyboard will show us the modified page and we’ll be able to navigate to our applicant system without typing the full web address in address bar of the browser. </p>
<p>You’ll notice our table for an applicant is empty - the reason is simple - we haven’t entered data in our database table. Before we enter data into our database table, let’s discuss how ASP MVC interprets retrieving and sending razor pages, as well as database access.</p>
<p>We'll continue by understanding the differences between  ASP  web forms and  ASP  MVC  @Html.ActionLink("next", "Index5").</p>